﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class SliderChange_2 : MonoBehaviour, IPointerUpHandler
{
    Slider slider;
    // Start is called before the first frame update
    void Start()
    {
        slider = this.GetComponent<Slider>();
        slider.onValueChanged.AddListener(
            (value) =>
            {
                Manage_2.instance.currentMusic = (int)value;
                SetSliderText((int)value);
                Vibrate();
            }
        );

        slider.minValue = GameData.minNumber + 3;
        slider.maxValue = GameData.maxNumber + 3;
        slider.value = GameData.returnNumber + 3;        
    }

    void SetSliderText(int index)
    {
        slider.GetComponentInChildren<Text>().text = (index - 3).ToString();
    }
    void Vibrate()
    {
        GameFunction.Vibrate(GameData.sliderVibrateIndex);
    }
    void AutoReturn()
    {
        if (slider.value != GameData.returnNumber + 3)
            slider.value = GameData.returnNumber + 3;
    }
    public void OnPointerUp(PointerEventData eventData)
    {
        if (GameData.autoReturn == true)
            AutoReturn();
    }
}
